package br.perfiman.faces;

import java.util.Calendar;

import br.perfiman.model.DTOs.IRS_DTO;
import br.perfiman.service.IRSService;
import br.perfiman.utils.ServiceLocator;

public class IrsBean extends BaseBean {
	protected IRSService service;

	private IRS_DTO entity;

	public IrsBean() throws Exception {
		service = getService();
		
		entity = new IRS_DTO();
		Calendar today = Calendar.getInstance();
		entity.setMonth(today.get(Calendar.MONTH) + 1);
		entity.setYear(today.get(Calendar.YEAR));
		retrieve();
	}

	@SuppressWarnings("unchecked")
	protected IRSService getService() throws Exception {
		if(service == null){
			service = (IRSService) ServiceLocator.getInstance().get("IRSServiceBean/remote");
		}
		return service;
	}
	
	public String retrieve() throws Exception {
		entity = service.getIRSByMonth(entity.getMonth(), entity.getYear());
		return null;
	}

	public IRS_DTO getEntity() {
		return entity;
	}

	public void setEntity(IRS_DTO entity) {
		this.entity = entity;
	}
}
